package com.wd.amodel.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import com.wd.amodel.bean.LinkageIndicatorInfo;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.List;

/**
 * NA<BR>
 *
 * @author w4425
 * @version [V2.0.0, 2021/4/26]
 * @since V2.0.0
 */
public class TabLinkageIndicatorAdapter extends CommonNavigatorAdapter {
    private List<LinkageIndicatorInfo> mChannels;

    public TabLinkageIndicatorAdapter(List<LinkageIndicatorInfo> mChannels) {
        this.mChannels = mChannels;
    }

    @Override
    public int getCount() {
        return mChannels == null ? 0 : mChannels.size();
    }

    @Override
    public IPagerTitleView getTitleView(Context context, int index) {
        SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);

        simplePagerTitleView.setText(mChannels.get(index).title);
        simplePagerTitleView.setNormalColor(Color.parseColor("#6C6C6C"));
        simplePagerTitleView.setSelectedColor(Color.parseColor("#0AACFF"));

        simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.setOnTextChange(index);
            }
        });

        return simplePagerTitleView;

    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator indicator = new LinePagerIndicator(context);
        indicator.setColors(Color.parseColor("#0AACFF"));
        return null;
    }

    private Callback callback;

    public interface Callback {
        /**
         * setOnTextChange
         *
         * @param index
         */
        void setOnTextChange(int index);
    }

    public void callbackActivity(Callback callback) {
        this.callback = callback;
    }
}
